Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't recover from "adjacent jsx elements" parser error #10682

Merged
merged 1 commit into from
Nov 8, 2019

Conversation

nicolo-ribaudo
Copy link
Member

Q                       A
Fixed Issues? prettier/prettier#6881
Patch: Bug Fix? Yes
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

Whenever we recover from a parser error, we have to build an invalid AST so that the recovered error is actionable by other tools.
While implementing error recovery, I missed that when we find adjacent JSX nodes I was just throwing away a lot of AST nodes.

This is causing problems with Prettier because, when we parse <a/><b/>, we just generate the AST for the first JSX element and thus prettier doesn't re-print the second one.

I considered wrapping the two nodes with a "fake" fragment, but I decided not to do it because of ASI which doesn't work with JSX elements: in this example, I would want to insert a comma after the first JSX element rather than having a fragment.

const el = do {
  let x = <span>x</span>

  <div>{x}</div>
}

@nicolo-ribaudo nicolo-ribaudo added PR: Bug Fix 🐛 A type of pull request used for our changelog categories pkg: parser area: errors labels Nov 8, 2019
@nicolo-ribaudo nicolo-ribaudo merged commit 0287c0f into babel:master Nov 8, 2019
@nicolo-ribaudo nicolo-ribaudo deleted the adjacent-jsx-throw branch November 8, 2019 20:23
@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Feb 8, 2020
@lock lock bot locked as resolved and limited conversation to collaborators Feb 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: errors outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: parser PR: Bug Fix 🐛 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants